/**************************************************************************
 *
 * Copyright (C) 2007 University of California, Los Angeles.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *************************************************************************/

package edu.ucla.cs.typecast.app.auction;

import java.io.*;
import java.net.*;

/**
 * Info about a participant (buyer or seller) of an auction.
 */

public class ParticipantInfo implements Serializable {
	/**
	 * Serial number for serialization.
	 */

	private static final long serialVersionUID = 1L;

	/**
	 * ID of this participant.
	 */

	protected int id;

	/**
	 * Name.
	 */

	protected String name;

	/**
	 * Address that can reach this participant.
	 */

	protected InetAddress host;

	/**
	 * Port that can reach this participant.
	 */

	protected int port;
	
	public ParticipantInfo(int id, String name, InetAddress host, int port) {
		super();

		if (id < 1 || name == null || host == null || port < 1 || port > 65535)
			throw new IllegalArgumentException();

		this.id = id;
		this.name = name;
		this.host = host;
		this.port = port;
	}

	public ParticipantInfo(int id, String name, String host, int port)
			throws UnknownHostException {
		this(id, name, InetAddress.getByName(host), port);
	}

	public boolean equals(Object o) {
		// Compare by all fields
		
		if (o instanceof ParticipantInfo) {
			ParticipantInfo pi = (ParticipantInfo) o;
			return id == pi.id && name.equals(pi.name) && host.equals(pi.host)
					&& port == pi.port;
		} else {
			return false;
		}
	}

	public InetAddress getHost() {
		return host;
	}

	public int getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public int getPort() {
		return port;
	}

	public void setHost(InetAddress host) {
		this.host = host;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setPort(int port) {
		this.port = port;
	}
}
